package view.gui.components {	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.InteractiveObject;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	/**
	 * ...
	 * @author Anthony
	 */
	public class TwoStatesButton extends Sprite
	{
		//------------------------------- statics ------------------------------\\
		
		//------------------------------ variables -----------------------------\\
		private var _buttonOne 			: Sprite;
		private var _buttonOnePreview 	: Sprite;
		private var _buttonTwo			: Sprite;
		private var _buttonTwoPreview 	: Sprite;
		
		//------------------------------ accessors -----------------------------\\
		
		//-------------------------- public functions --------------------------\\
		public function TwoStatesButton(buttonOne : DisplayObject, buttonTwo : DisplayObject, buttonOnePreview : DisplayObject = null, buttonTwoPreview : DisplayObject = null)
		{
			_buttonOne = new Sprite();
			_buttonOne.visible = true;
			addChild(_buttonOne);
			_buttonOne.addChild(buttonOne);
			
			_buttonTwo = new Sprite();			
			_buttonTwo.visible = false;
			addChild(_buttonTwo);			
			_buttonTwo.addChild(buttonTwo);			
			
			_buttonOnePreview = new Sprite();
			_buttonOnePreview.visible = false;
			addChild(_buttonOnePreview);			
			if (buttonOnePreview == null)
			{
				var defaultButtonOnePreview : Bitmap = new Bitmap(new BitmapData(buttonOne.width, buttonOne.height));
				defaultButtonOnePreview.bitmapData.draw(buttonOne, null, new ColorTransform(1.2, 1.2, 1.2));
				_buttonOnePreview.addChild(defaultButtonOnePreview);
			}
			else
				_buttonOnePreview.addChild(buttonOnePreview);
			
			_buttonTwoPreview = new Sprite();
			_buttonTwoPreview.visible = false;
			addChild(_buttonTwoPreview);			
			if (buttonTwoPreview == null)
			{
				var defaultButtonTwoPreview : Bitmap = new Bitmap(new BitmapData(buttonTwo.width, buttonTwo.height));
				defaultButtonTwoPreview.bitmapData.draw(buttonTwo, null, new ColorTransform(1.2, 1.2, 1.2));
				_buttonTwoPreview.addChild(defaultButtonTwoPreview);
			}
			else
				_buttonTwoPreview.addChild(buttonTwoPreview);
			
			addEventListener(MouseEvent.CLICK, switchState);
			addEventListener(MouseEvent.ROLL_OVER, showOtherStateButton);
		}
		
		//------------------------- private functions --------------------------\\
		private function switchState(e : MouseEvent) : void
		{
			_buttonOne.visible = !_buttonOne.visible;
			_buttonTwo.visible = !_buttonTwo.visible;			
			_buttonOnePreview.visible = false;
			_buttonTwoPreview.visible = false;
		}
		
		private function showOtherStateButton(e : MouseEvent) : void
		{
			addEventListener(MouseEvent.ROLL_OUT, hideOtherStateButton);			
			_buttonOnePreview.visible = _buttonTwo.visible;
			_buttonTwoPreview.visible = _buttonOne.visible;
		}
		
		private function hideOtherStateButton(e : MouseEvent) : void
		{
			removeEventListener(MouseEvent.ROLL_OUT, hideOtherStateButton);			
			_buttonOnePreview.visible = false;
			_buttonTwoPreview.visible = false;
		}
		
	}	
}